﻿<div class="avatar">
    <div class="avatarswf">
        <object id="avatarswf" height="350px" width="520px" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">
            <param name="movie" value="/misc/avatarmaker.swf?r=@Guid.NewGuid()" />
            <embed name="avatarswf" height="350px" width="520px"  type="application/x-shockwave-flash" src="/misc/avatarmaker.swf?r=@Guid.NewGuid()" />
        </object>
    </div>
    <div class="row-fluid">
        <div class="span6">
            <div class="avatar-tip">
                初始化中......</div>
        </div>
        <div class="span6">
            <div class="avatar-submit" style="display: none;">
                <a href="javascript:void(0);" onclick="uploadAvatar();">
                    <img src="http://static.silenthink.com/images/user.pic.save.jpg" alt="保存图像" />
                </a>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var avatar = null;
    function tipHandler(msg) {
        $(".avatar-tip").html("<span style='color:red;'>" + msg + "</span>");
    }
    function jsHandler(result) {
        var json = $.parseJSON(result);
        if (json.Status) {
            $(".avatar-tip").html("<span style='color:green;'>保存图像成功</span>");
            document.getElementById('avatar').src = json.Data + "?r=" + Math.random();
            $.fancybox.close();
            avatar = null;
        }
        else {
            $(".avatar-tip").html("<span style='color:red;'>保存图像失败</span>");
        }
    }
    function initFlash() {
        avatar = document['avatarswf'] || window['avatarswf']; // document.getElementById('avatarswf');
        var status = avatar.flashInit() || false;
        if (status) {
            avatar.setJSFuncName(['jsHandler', 'tipHandler']);
            $(".avatar-tip").empty();
            $(".avatar-submit").show();
        }
    }
    function uploadAvatar() {
        avatar.upload('/home/avatar');
    }
    setTimeout(initFlash, 2000);
</script>
